Differentiating function with two or more terms